package speedball;

import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Ellipse;
import javafx.scene.shape.Rectangle;
import speedball.EffectManage.JavaFxConstants ;

public class SpProgressBar extends AnchorPane{

    private Rectangle border;
//当前值
    private Rectangle value;
//差值
    private Rectangle dvalue;

    private Ellipse top;

    private double maxValue =100.00D;
    private double minValue =0.00D;
    private double visibleMaxValue =100.00D;
    private double visibleMinValue =0.00D;
    private double currentValue =90.00D;

    private double longth =65.00D;
    private double progressBarValueWidth ;

    public  SpProgressBar(double currentValue, JavaFxConstants direction,boolean visible,double opacity){

       this.currentValue=currentValue;
       progressBarValueWidth = currentValue/maxValue*(longth-2);


       if(direction==JavaFxConstants.HORIZONTAL){
           border = ShapeManage.createRectangle(0 , 0,longth, 8, 8, 8);

           value = ShapeManage.createRectangle(border.getX()+1, border.getY()+1,
                   progressBarValueWidth, 6, 6, 6);

           dvalue=ShapeManage.createRectangle(border.getX()+progressBarValueWidth-1, border.getY()+1,
                   longth-progressBarValueWidth,6,  6, 6);

           top = ShapeManage.createEllipse(3D, 1.5D    ,3D);
           top.setLayoutX(value.getX()+value.getWidth()-value.getHeight()/2);
           top.setLayoutY(value.getY());
       }else if(direction==JavaFxConstants.VERTICAL){
		border = ShapeManage.createRectangle(0 , 0,
                8, longth, 8, 8);

		value = ShapeManage.createRectangle(border.getX()+1,  border.getHeight()-1-progressBarValueWidth,
                6,progressBarValueWidth,  6, 6);

        dvalue=ShapeManage.createRectangle(border.getX()+1, border.getY()+1,
                6,longth-progressBarValueWidth,  6, 6);

		top = ShapeManage.createEllipse(3D, 3D ,1.5D);
           top.setLayoutX(value.getX());
           top.setLayoutY(value.getY()-value.getWidth()/2+1);
       }
//        setStyle("-fx-background-color: yellow");

        border.setStroke(Color.rgb(234,236,242));
        border.setStrokeWidth(1.5D);
        border.setFill(null);
        value.setStroke(Color.rgb(113,239,124));
        value.setFill(Color.rgb(113,239,124));
        top.setStroke(Color.rgb(24,183,92));
        top.setFill(Color.rgb(24,183,92));

        dvalue.setFill(Color.rgb(173,173,173));
        dvalue.setStroke(Color.rgb(173,173,173));
        visible(visible);
        opacity(opacity);
        getChildren().addAll(border, value,dvalue,top);
    }

    public void visible(boolean visible) {
        setVisible(visible);
    }

//    public void visible(boolean visible) {
//        border.setVisible(visible);
//        value.setVisible(visible);
//        top.setVisible(visible);
//    }
        public void opacity(double opacity) {
        setOpacity(opacity);
    }


//    public void opacity(double opacity) {
//        border.setOpacity(opacity);
//        value.setOpacity(opacity);
//        top.setOpacity(opacity);
//    }


    public Rectangle getMyBorder() {
        return border;
    }

    public void setMyBorder(Rectangle border) {
        this.border = border;
    }

    public Rectangle getValue() {
        return value;
    }

    public void setValue(Rectangle value) {
        this.value = value;
    }

    public Ellipse getTop() {
        return top;
    }

    public void setTop(Ellipse top) {
        this.top = top;
    }

    public double getMaxValue() {
        return maxValue;
    }

    public void setMaxValue(double maxValue) {
        this.maxValue = maxValue;
    }

    public double getMinValue() {
        return minValue;
    }

    public void setMinValue(double minValue) {
        this.minValue = minValue;
    }

    public double getVisibleMaxValue() {
        return visibleMaxValue;
    }

    public void setVisibleMaxValue(double visibleMaxValue) {
        this.visibleMaxValue = visibleMaxValue;
    }

    public double getVisibleMinValue() {
        return visibleMinValue;
    }

    public void setVisibleMinValue(double visibleMinValue) {
        this.visibleMinValue = visibleMinValue;
    }

    public double getCurrentValue() {
        return currentValue;
    }

    public void setCurrentValue(double currentValue) {
        this.currentValue = currentValue;
    }

    public double getLongth() {
        return longth;
    }

    public void setLongth(double longth) {
        this.longth = longth;
    }

    public double getProgressBarValueWidth() {
        return progressBarValueWidth;
    }

    public void setProgressBarValueWidth(double progressBarValueWidth) {
        this.progressBarValueWidth = progressBarValueWidth;
    }
}
